<template>
  <div class="searchStu">
    <el-select v-model="searchType" clearable placeholder="搜索类型">
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>

    <el-input
      placeholder="请输入搜索内容-模糊查询"
      v-model="searchValue"
      clearable
    >
    </el-input>

    <el-button type="primary" plain @click="search()">搜索</el-button>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapMutations: stuMapMutations, mapActions: stuMapActions } =
  createNamespacedHelpers("student");

export default {
  data() {
    return {
      searchType: "name",
      searchValue: "",
      options: [
        { value: "name", label: "姓名" },
        { value: "age", label: "年龄" },
        { value: "gender", label: "性别" },
      ],
    };
  },
  methods: {
    ...stuMapMutations([
      "changeSearchType",
      "changeSearchValue",
      "toggleCurrentPage",
    ]),
    ...stuMapActions(["getStudent"]),
    search() {
      //搜索前修改页码
      this.toggleCurrentPage(1);
      //更新搜索数据
      this.changeSearchType(this.searchType);
      this.changeSearchValue(this.searchValue);
      //执行搜索
      this.getStudent();
    },
  },
};
</script>

<style scoped>
.searchStu {
  width: 100%;
  display: flex;
  justify-content: center;

}
.el-select {
  width: 110px;
}
.el-input {
  width: 50%;
}
</style>